package com.pay.ioopos.activity;

import android.content.Intent;
import android.os.Bundle;

import com.pay.ioopos.KeyInfo;
import com.pay.ioopos.R;
import com.pay.ioopos.fragment.DeviceInfoFragment;
import com.pay.ioopos.fragment.SettingFragment;
import com.pay.ioopos.fragment.StatisticsMenuFragment;
import com.pay.ioopos.fragment.StatisticsOverviewFragment;

import static com.pay.ioopos.KeyInfo.KEY_CANCEL;
import static com.pay.ioopos.KeyInfo.KEY_ENTER;
import static com.pay.ioopos.KeyInfo.KEY_NUM_1;
import static com.pay.ioopos.KeyInfo.KEY_NUM_2;
import static com.pay.ioopos.KeyInfo.KEY_NUM_3;
import static com.pay.ioopos.KeyInfo.KEY_NUM_4;
import static com.pay.ioopos.PayMode.FIXED;
import static com.pay.ioopos.PayMode.NORMAL;

public class SettingActivity extends AbstractActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        setMainFragment(new SettingFragment());
    }

    @Override
    public boolean onKeyDown(KeyInfo keyInfo) {
        if (mainFragment instanceof SettingFragment) {
            if (keyInfo == KEY_ENTER || keyInfo == KEY_CANCEL) {
                Intent intent = new Intent(this, MainActivity.class);
                startActivity(intent);
            } else if (keyInfo == KEY_NUM_1) {
                Intent intent = new Intent(this, ModeActivity.class);
                intent.putExtra("mode", NORMAL.ordinal());
                startActivity(intent);
            } else if (keyInfo == KEY_NUM_2) {
                Intent intent = new Intent(this, ModeActivity.class);
                intent.putExtra("mode", FIXED.ordinal());
                startActivity(intent);
            } else if (keyInfo == KEY_NUM_3) {
                Intent intent = new Intent(this, ConnectActivity.class);
                startActivity(intent);
            } else if (keyInfo == KEY_NUM_4) {
                Intent intent = new Intent(this, SystemActivity.class);
                startActivity(intent);
            }
        } else if (mainFragment instanceof StatisticsOverviewFragment || mainFragment instanceof DeviceInfoFragment) {
            if (keyInfo == KEY_ENTER || keyInfo == KEY_CANCEL) {
                setMainFragment(new StatisticsMenuFragment());
            }
        }
        return false;
    }

}
